package o;

import android.graphics.PointF;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.ActivityChooserView.ActivityChooserViewAdapter;
import androidx.recyclerview.widget.RecyclerView.j;
import androidx.recyclerview.widget.RecyclerView.q.c;

public class mn extends mu {
    @Nullable
    private mq ˊ;
    @Nullable
    private mq ˎ;

    public int[] ˏ(@NonNull j jVar, @NonNull View view) {
        int[] iArr = new int[2];
        if (jVar.ʻ()) {
            iArr[0] = ॱ(jVar, view, ˊ(jVar));
        } else {
            iArr[0] = 0;
        }
        if (jVar.ʼ()) {
            iArr[1] = ॱ(jVar, view, ˎ(jVar));
        } else {
            iArr[1] = 0;
        }
        return iArr;
    }

    public int ˏ(j jVar, int i, int i2) {
        if (!(jVar instanceof c)) {
            return -1;
        }
        int ˌ = jVar.ˌ();
        if (ˌ == 0) {
            return -1;
        }
        View ॱ = ॱ(jVar);
        if (ॱ == null) {
            return -1;
        }
        int ˎ = jVar.ˎ(ॱ);
        if (ˎ == -1) {
            return -1;
        }
        PointF ˎ2 = ((c) jVar).ˎ(ˌ - 1);
        if (ˎ2 == null) {
            return -1;
        }
        int ˏ;
        int ˏ2;
        if (jVar.ʻ()) {
            ˏ = ˏ(jVar, ˊ(jVar), i, 0);
            if (ˎ2.x < 0.0f) {
                ˏ = -ˏ;
            }
        } else {
            ˏ = 0;
        }
        if (jVar.ʼ()) {
            ˏ2 = ˏ(jVar, ˎ(jVar), 0, i2);
            if (ˎ2.y < 0.0f) {
                ˏ2 = -ˏ2;
            }
        } else {
            ˏ2 = 0;
        }
        if (!jVar.ʼ()) {
            ˏ2 = ˏ;
        }
        if (ˏ2 == 0) {
            return -1;
        }
        ˏ = ˎ + ˏ2;
        if (ˏ < 0) {
            ˏ = 0;
        }
        if (ˏ >= ˌ) {
            return ˌ - 1;
        }
        return ˏ;
    }

    public View ॱ(j jVar) {
        if (jVar.ʼ()) {
            return ˎ(jVar, ˎ(jVar));
        }
        if (jVar.ʻ()) {
            return ˎ(jVar, ˊ(jVar));
        }
        return null;
    }

    private int ॱ(@NonNull j jVar, @NonNull View view, mq mqVar) {
        int ˏ;
        int ˊ = (mqVar.ˊ(view) / 2) + mqVar.ˋ(view);
        if (jVar.ʿ()) {
            ˏ = mqVar.ˏ() + (mqVar.ʻ() / 2);
        } else {
            ˏ = mqVar.ॱ() / 2;
        }
        return ˊ - ˏ;
    }

    private int ˏ(j jVar, mq mqVar, int i, int i2) {
        int[] ˏ = ˏ(i, i2);
        float ˋ = ˋ(jVar, mqVar);
        if (ˋ <= 0.0f) {
            return 0;
        }
        return Math.round(((float) (Math.abs(ˏ[0]) > Math.abs(ˏ[1]) ? ˏ[0] : ˏ[1])) / ˋ);
    }

    @Nullable
    private View ˎ(j jVar, mq mqVar) {
        View view = null;
        int ˈ = jVar.ˈ();
        if (ˈ != 0) {
            int ˏ;
            if (jVar.ʿ()) {
                ˏ = mqVar.ˏ() + (mqVar.ʻ() / 2);
            } else {
                ˏ = mqVar.ॱ() / 2;
            }
            int i = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
            int i2 = 0;
            while (i2 < ˈ) {
                View view2;
                View ᐝ = jVar.ᐝ(i2);
                int abs = Math.abs((mqVar.ˋ(ᐝ) + (mqVar.ˊ(ᐝ) / 2)) - ˏ);
                if (abs < i) {
                    view2 = ᐝ;
                } else {
                    abs = i;
                    view2 = view;
                }
                i2++;
                view = view2;
                i = abs;
            }
        }
        return view;
    }

    private float ˋ(j jVar, mq mqVar) {
        View view = null;
        int i = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
        int ˈ = jVar.ˈ();
        if (ˈ == 0) {
            return 1.0f;
        }
        int i2 = 0;
        View view2 = null;
        int i3 = Integer.MIN_VALUE;
        while (i2 < ˈ) {
            View view3;
            View ᐝ = jVar.ᐝ(i2);
            int ˎ = jVar.ˎ(ᐝ);
            if (ˎ == -1) {
                ˎ = i;
                view3 = view;
                view = view2;
            } else {
                if (ˎ < i) {
                    i = ˎ;
                    view2 = ᐝ;
                }
                if (ˎ > i3) {
                    i3 = ˎ;
                    view = view2;
                    ˎ = i;
                    view3 = ᐝ;
                } else {
                    ˎ = i;
                    view3 = view;
                    view = view2;
                }
            }
            i2++;
            view2 = view;
            view = view3;
            i = ˎ;
        }
        if (view2 == null || view == null) {
            return 1.0f;
        }
        ˎ = Math.max(mqVar.ॱ(view2), mqVar.ॱ(view)) - Math.min(mqVar.ˋ(view2), mqVar.ˋ(view));
        if (ˎ == 0) {
            return 1.0f;
        }
        return (((float) ˎ) * 1.0f) / ((float) ((i3 - i) + 1));
    }

    @NonNull
    private mq ˎ(@NonNull j jVar) {
        if (this.ˎ == null || this.ˎ.ॱ != jVar) {
            this.ˎ = mq.ˋ(jVar);
        }
        return this.ˎ;
    }

    @NonNull
    private mq ˊ(@NonNull j jVar) {
        if (this.ˊ == null || this.ˊ.ॱ != jVar) {
            this.ˊ = mq.ˏ(jVar);
        }
        return this.ˊ;
    }
}
